cellRank builds a graph based on a transition matrix. The transition matrix contains the probabilities of cell–>cell transitions, which are calculated as a weighted average between (similarity of velocity vector and cell difference vector) and (euclidean similarity in PCA space). Here, we want to compare this graph to the graph that we build using projectedNeighbors.

Setup and get data from scVelo

Use the reticulate package to use scVelo/cellrank from within R:

load complete adata from previous run

load pancreas data

Run scVelo

Run velocity

Run cellrank

Save adata to speed up later

Extract transition matrices

## <Conn[dnorm=True]>
## <Velo[softmax_scale=3.8, mode=deterministic, seed=10286]>

Weighted graphs from transition matrices
adjacency = transition matrix –> fdg
Distances: transition matrix using just euclidean similarity
Velocities: transition matrix using just velocity correlation
Combined: transition matrix = weighted average of distance and velocity
(using default weight 0.8velocity + 0.2distance)

Varying weight in weighted average

Use composite distance

Extract count data..

Filter genes

(Downsample cells to make things easier)

Normalize for dimensional reduction

## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...

Dimensional reduction

Run velocyto on panc data

## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
## [1] "Calculating variance fit ..."
## [1] "Using gam with k=5..."
## [1] "301 overdispersed genes ... "
## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
## [1] "Calculating variance fit ..."
## [1] "Using gam with k=5..."
## [1] "451 overdispersed genes ... "

Scores of observed and projected states in PC space

Graph visualization on subset of cells from PC coordinates

## [1] "Done finding neighbors"
## [1] "calculating weights"
## [1] "Done making graph"

Comparing graphs from each method